package code_generator;

import java.math.BigDecimal;

public class CodeInit {
	
	public final static String OutputHead = "import java.math.*;\nimport java.io.*;\nimport java.util.*;\npublic class XBDPL {\n"
			+ "public static Integer add(Integer a, Integer b){\nreturn a+b;\n}\n"
			+ "public static BigDecimal add(BigDecimal a, BigDecimal b){\nreturn a.add(b);\n}\n"
			+ "public static Integer sub(Integer a, Integer b){\nreturn a-b;\n}\n"
			+ "public static BigDecimal sub(BigDecimal a, BigDecimal b){\nreturn a.subtract(b);\n}\n"
			+ "public static Integer mul(Integer a, Integer b){\nreturn a*b;\n}\n"
			+ "public static BigDecimal mul(BigDecimal a, BigDecimal b){\nreturn a.multiply(b);\n}\n"
			+ "public static Integer divide(Integer a, Integer b){\nreturn a / b;\n}\n"
			+ "public static BigDecimal divide(BigDecimal a, BigDecimal b){\nreturn a.divide(b,1000,RoundingMode.HALF_UP);\n}\n"
			+ "public static Integer mod(Integer a, Integer b){\nreturn a % b;\n}\n"
			+ "public static BigDecimal mod(BigDecimal a, BigDecimal b){\nreturn a.remainder(b);\n}\n"
			+ "public static Boolean equals(Integer a, Integer b){\nreturn a == b;\n}\n"
			+ "public static Boolean equals(BigDecimal a, BigDecimal b){\nreturn a.equals(b);\n}\n"
			+ "public static Boolean equals(boolean a, boolean b){\nreturn a==b;\n}"
			+ "public static Boolean neq(Integer a, Integer b){\nreturn a != b;\n}\n"
			+ "public static Boolean neq(BigDecimal a, BigDecimal b){\nreturn !a.equals(b);\n}\n"
			+ "public static Integer negate(Integer a){\nreturn -a;\n}\n"
			+ "public static BigDecimal negate(BigDecimal  a){\nreturn a.negate();\n}\n"
			+ "public static Boolean gtr(Integer a, Integer b){\nreturn a>b;\n}\n"
			+ "public static Boolean gtr(BigDecimal a, BigDecimal b){\nif(a.compareTo(b) == 1)\nreturn true;\nelse\nreturn false;\n}\n"
			+ "public static Boolean gtr_eq(Integer a, Integer b){\nreturn a>=b;\n}\n"
			+ "public static Boolean gtr_eq(BigDecimal a, BigDecimal b){\nif(a.compareTo(b) == -1)\nreturn false;\nelse\nreturn true;\n}\n"
			+ "public static Boolean less(Integer a, Integer b){\nreturn a < b;\n}\n"
			+ "public static Boolean less(BigDecimal a, BigDecimal b){\nif(a.compareTo(b) == -1)\nreturn true;\nelse\nreturn false;\n}\n"
			+ "public static Boolean less_eq(Integer a, Integer b){\nreturn a <= b;\n}\n"
			+ "public static Boolean less_eq(BigDecimal a, BigDecimal b){\nif(a.compareTo(b) == 1)\nreturn false;\nelse\nreturn true;\n}\n"
			+ "public static BigDecimal toBig(Integer i){\n return new BigDecimal(String.valueOf(i)+\".0\");\n}\n"
			+ "public static Integer smallRand(){\nreturn (int)(Math.random()*10000);\n}\n"
			+ "public static BigDecimal bigRand(){\nStringBuffer s = new StringBuffer(\"0.\");\nfor(;s.length()<1002;){\ns.append((int)(Math.random()*10));}\nreturn new BigDecimal(s.toString());\n}"
			+ "/*************************************************************************************/\n"
		    + "public static String output(String s, int digits){\n" 
			+ "StringBuffer result = new StringBuffer();\n"
			+ "int zeros;\n"
			+ "int length;\n"
			+ "Boolean oversize = false;\n"
			+ "Boolean isNeg = false;\n"	
			+ "if(s.startsWith(\"-\")){\n"
			+ "	isNeg = true;\n"
			+ "	s=s.substring(1,s.length());\n"
			+ "	}\n"
			+ "if(s.contains(\".\")){\n"
			+ "	if(s.startsWith(\"0\")){\n"
			+ "		zeros=1;\n"
			+ "		int i;\n"
			+ "		for(i = 2;s.substring(i, i+1).equals(\"0\");i++){\n"
			+ "			if(s.substring(i, i+1).equals(\"0\")){\n"
			+ "				zeros+=1;\n"
			+ "			}\n"
			+ "		}\n"
			+ "		result.append(s.substring(i,i+1));\n"
			+ "		result.append(\".\");\n"
			+ "		if(digits<s.length()-i+1){\n"
			+ "			result.append(s.subSequence(i+1, i+digits));\n"
			+ "		}else{\n"
			+ "			result.append(s.subSequence(i+1, s.length()-1));\n"
			+ "			for(int j = 0; j<s.length()-i-3;j++)\n"
			+ "				result.append(\"0\");\n"
			+ "		}\n"
			+ "		result.append(\" E -\" + zeros);\n"
			+ "	}else{\n"
			+ "		int i;\n"
			+ "		length = 0;\n"
			+ "		for(i = 0;!s.substring(i, i+1).equals(\".\");i++){\n"
			+ "			if(!s.substring(i, i+1).equals(\".\")){\n"
			+ "				length+=1;\n"
			+ "			}\n"
			+ "		}\n"
			+ "		if(length>digits){\n"
			+ "			result.append(s.substring(0,1));\n"
			+ "			result.append(\".\");\n"
			+ "			result.append(s.subSequence(1, digits));\n"
			+ "			result.append(\" E\" + length);\n"
			+ "		}else{\n"
			+ "			result.append(s.substring(0,1));\n"
			+ "			result.append(\".\");\n"
			+ "			if(length!=1){\n"
			+ "				if(digits<s.length()-1){\n"
			+ "					result.append(s.subSequence(1, length));\n"
			+ "					result.append(s.subSequence(length+1,digits+1));\n"
			+ "				}else{\n"
			+ "					result.append(s.subSequence(1, length));\n"
			+ "					result.append(s.subSequence(length+1,s.length()));\n"
			+ "					for(int j =0; j<digits-s.length()+1;j++){\n"
			+ "						result.append(\"0\");\n"
			+ "					}\n"
			+ "				}\n"
			+ "			}else{\n"
			+ "				result.append(s.subSequence(2, digits+1));\n"
			+ "			}\n"
			+ "			result.append(\" E\" + length);\n"
			+ "		}\n"
			+ "	}\n"
			+ "}else{\n"
			+ "	length = s.length();\n"
			+ "	if(digits<s.length()){\n"
			+ "		result.append(s.substring(0,1));\n"
			+ "		result.append(\".\");\n"
			+ "		result.append(s.subSequence(1, digits));\n"
			+ "		result.append(\" E\" + length);\n"
			+ "	}else{\n"
			+ "		result.append(s.substring(0,1));\n"
			+ "		result.append(\".\");\n"
			+ "		result.append(s.subSequence(1, s.length()));\n"
			+ "		for(int j =0; j<digits-s.length();j++){\n"
			+ "			result.append(\"0\");\n"
			+ "		}\n"
			+ "		result.append(\" E\" + length);\n"
			+ "	}\n"
			+ "}\n"
			+ "if(isNeg){\n"
			+ "	StringBuffer result1 = new StringBuffer();\n"
			+ "	result1.append(\"-\" + result);\n"
			+ "	return result1.toString();\n"
			+ "}\n"
			+ "return result.toString();\n"
			+ "}\n";
	public final static String OutputTail = "}\n";
	
}
